// <copyright file="DataTableColumn.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

namespace YUIAspNet
{
    /// <summary>
    /// Represents a column in a DataTable
    /// </summary>
    public class DataTableColumn
    {
        IDataTableFormat _templateFormat;

        /// <summary>
        /// Initializes a new instance of the <see cref="DataTableColumn"/> class.
        /// </summary>
        public DataTableColumn()
        {
            Visible = true;
        }

        #region Public properties
        /// <summary>
        /// Gets or sets the abbreviation.
        /// </summary>
        /// <value>The abbr.</value>
        public string Abbr { get; set; }

        /// <summary>
        /// Gets or sets the children.
        /// </summary>
        /// <value>The children.</value>
        public string Children { get; set; }

        /// <summary>
        /// Gets or sets the name of the class.
        /// </summary>
        /// <value>The name of the class.</value>
        public string ClassName { get; set; }

        /// <summary>
        /// Gets or sets the field.
        /// </summary>
        /// <value>The field.</value>
        public string Field { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="DataTableColumn"/> is visible.
        /// </summary>
        /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
        public bool Visible { get; set; }

        /// <summary>
        /// Gets or sets the key.
        /// </summary>
        /// <value>The key.</value>
        public string Key { get; set; }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        /// <value>The text.</value>
        public string Text { get; set; }

        /// <summary>
        /// Gets or sets the max auto width.
        /// </summary>
        /// <value>The max auto width.</value>
        public int MaxAutoWidth { get; set; }

        /// <summary>
        /// Gets or sets the min width.
        /// </summary>
        /// <value>The min width.</value>
        public int MinWidth { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="DataTableColumn"/> is resizeable.
        /// </summary>
        /// <value><c>true</c> if resizeable; otherwise, <c>false</c>.</value>
        public bool Resizeable { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="DataTableColumn"/> is selected.
        /// </summary>
        /// <value><c>true</c> if selected; otherwise, <c>false</c>.</value>
        public bool Selected { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="DataTableColumn"/> is sortable.
        /// </summary>
        /// <value><c>true</c> if sortable; otherwise, <c>false</c>.</value>
        public bool Sortable { get; set; }

        /// <summary>
        /// Gets or sets the width.
        /// </summary>
        /// <value>The width.</value>
        public int Width { get; set; }

        /// <summary>
        /// Gets or sets the format.
        /// </summary>
        /// <value>The format.</value>
        public ColumnFormat Format { get; private set; }

        /// <summary>
        /// Gets or sets the template format.
        /// </summary>
        /// <value>The template format.</value>
        public IDataTableFormat TemplateFormat
        {
            get { return _templateFormat; }
            set
            {
                _templateFormat = value;

                if (value == null)
                    Format = ColumnFormat.String;
                else if (_templateFormat is NumberFormat && !(_templateFormat is CurrencyFormat))
                    Format = ColumnFormat.Number;
                else if (_templateFormat is CurrencyFormat)
                    Format = ColumnFormat.Currency;
                else if (_templateFormat is DateFormat)
                    Format = ColumnFormat.Date;
                else if (_templateFormat is TemplateFormat)
                    Format = ColumnFormat.Template;
                else if (_templateFormat is JavascriptFunctionFormat)
                    Format = ColumnFormat.JSFunction;
            }
        } 
        #endregion
    }

    /// <summary>
    /// Format of the column.
    /// </summary>
    public enum ColumnFormat 
    {
        /// <summary>
        /// String column, the default option.
        /// </summary>
        String = 0,

        /// <summary>
        /// Represents a date column
        /// </summary>
        Date,

        /// <summary>
        /// Represents a numeric column
        /// </summary>
        Number,

        /// <summary>
        /// Represents a currency column
        /// </summary>
        Currency,

        /// <summary>
        /// Represents a template column
        /// </summary>
        Template,

        /// <summary>
        /// Represents a javascript function column.
        /// </summary>
        JSFunction
    }
}
